using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace LibGreen.Jabber.ProtocolElements.SaslElements
{
    /// <summary>
    /// Describes the &lt;challenge&gt; element
    /// </summary>
    class ChallengeElement
    {
        private readonly string challengeData;

        /// <summary>
        /// Initializes a ChallengeElement from a received <see cref="Element"/>
        /// </summary>
        /// <param name="element">The received <see cref="Element"/> containing the &lt;challenge&gt; stanza</param>
        public ChallengeElement(Element element)
        {
            challengeData = element.Value;
            if (!String.IsNullOrEmpty(challengeData) && challengeData.Length > 1)
            {
                challengeData = Encoding.UTF8.GetString(Convert.FromBase64String(challengeData));
            }
        }

        /// <summary>
        /// Gets the plaintext challenge data sent from the server
        /// </summary>
        public string ChallengeData
        {
            get { return challengeData; }
        }
    }
}
